/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Admission;

import Academic.AcademicBean;
import Address.AddressBean;
import Category.CategoryBean;
import Country.CountryBean;
import Course.CourseBean;
import Facility.FacilityBean;
import Parents.ParentsBean;
import State.StateBean;
import Student.StudentBean;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author mishra
 */
public class AdmissionList extends HttpServlet {

    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            Vector<Object> list;
            list = Admission.Query.viewAll();
           if(!list.isEmpty())
           {
               Iterator it=list.iterator();
               while(it.hasNext())
               {
                  AdmissionBean ab=(AdmissionBean)it.next();
                  CourseBean cb=ab.getCourseBean();
                  StudentBean sb=ab.getStudentBean();
                  CategoryBean cab=ab.getCategoryBean();
                  AddressBean adb=sb.getAddressBean();
                  StateBean stb=adb.getStateBean();
                  CountryBean cob=stb.getCountryBean();
                  ParentsBean pb=ab.getParentsBean();
                  AddressBean adbp=pb.getAddressBean();
                  StateBean stbp=adbp.getStateBean();
                  CountryBean cobp=adbp.getCountryBean();
                  AcademicBean acb=ab.getAcademicBean();
                  FacilityBean fb=ab.getFacilityBean();
                  
                  
                  out.println("<tr id='"+ab.getAddmissionId()+"'>");
                  String gen="";
                 
                  out.println("<td>");
                  out.println("<b>Student Roll No.:</b>&nbsp"+ab.getRollNumber()+"<br><b>Admission Id:</b>&nbsp"+ab.getAddmissionId()+"<br><b>Email:</b>&nbsp"+ab.getStudentEmail()+"<br><b>Mobile No:</b>&nbsp"+ab.getStudentMobile()+"<br><b>Session:</b>&nbsp"+ab.getStudentSession()+"<br><b>Course:</b>&nbsp"+cb.getCourseName()+"<br><b>Stream:</b>&nbsp"+cb.getStream()+"<br><b>Semester:</b>&nbsp"+ab.getSemester()+"<br><b>Application No:</b>&nbsp"+ab.getApplicationNo()+"<br><b>Addmission Date:</b>&nbsp"+ab.getAdmissionDate());
                  out.println("</td>");
                  out.println("<td>");
                  out.println("<b>Student Name:</b>&nbsp"+sb.getStudentName()+"<br><b>Gender:</b>&nbsp"+sb.getGender()+"<br><b>Category:</b>&nbsp"+cab.getCategory()+"<br><b>Address1:</b>&nbsp"+adb.getAddress1()+"<br><b>Address2:</b>&nbsp"+adb.getAddress2()+"<br><b>Pin Code:</b>&nbsp"+adb.getPinCode());
                  out.println("</td>");
                  out.println("<td>");
                  out.println("<b>Father Name:</b>&nbsp"+pb.getFatherName()+"<br><b>Father Occupation:</b>&nbsp"+pb.getFatherOccupation()+"<br><b>Father Mobile:</b>&nbsp"+pb.getFatherMobileNo()+"<br><b>Mother Name:</b>&nbsp"+pb.getMotherName()+"<br><b>Mother Occupation:</b>&nbsp"+pb.getMotherOccupation()+"<br><b>Mother Mobile:</b>&nbsp"+pb.getMotherMobileNo()+"<br><b>Guardian Name:</b>&nbsp"+pb.getGuardianName()+"<br><b>Relation:</b>&nbsp"+pb.getRelation()+"<br><b>Guardian Occupation:</b>&nbsp"+pb.getGuardianOccupation()+"<br><b>Guardian Mobile:</b>&nbsp"+pb.getGuardianMobileNo());
                  out.println("</td>");
                  out.println("<td>");
                  out.println("<b>HS School/College Name:</b>&nbsp"+acb.getHighSchool()+"<br><b>HS. Board Name:</b>&nbsp"+acb.getHighBoardName()+"<br><b>HS. Obtain Marks:</b>&nbsp"+acb.getHighMarksObtained()+"<br><b>HS. Maximum Marks:</b>&nbsp"+acb.getHighMaxMarks()+"<br><b>IM. School/College Name:</b>&nbsp"+acb.getInterSchool()+"<br><b>IM. Board Name:</b>&nbsp"+acb.getInterBoardName()+"<br><b>IM. Obtain Marks:</b>&nbsp"+acb.getInterMarksObtained()+"<br><b>IM. Maximum Marks:</b>&nbsp"+acb.getInterMaxMarks()+"<br><b>Other School/College Name:</b>&nbsp"+acb.getOther()+"<br><b>Other Board Name:</b>&nbsp"+acb.getOtherBoardName()+"<br><b>Other Obtain Marks:</b>&nbsp"+acb.getOhterMarksObtained()+"<br><b>Other Maximum Marks:</b>&nbsp"+acb.getOtherMaxMarks());
                  out.println("</td>");
                  out.println("<td>");
                  String trans;
                  String hostel;
                  String mess;
                  if(fb.getTransportationStatus()==1)
                  {
                      trans="Yes";
                  }
                  else
                  {
                     trans="No"; 
                  }
                   if(fb.getHostelStatus()==1)
                  {
                      hostel="Yes";
                  }
                  else
                  {
                     hostel="No"; 
                  }
                    if(fb.getMessStatus()==1)
                  {
                      mess="Yes";
                  }
                  else
                  {
                     mess="No"; 
                  }
                   String appdate=ab.getAdmissionDate().toString();
                   String appd[]=appdate.split("-");
                   String aapdate=Integer.parseInt(appd[1])+"/"+Integer.parseInt(appd[2])+"/"+Integer.parseInt(appd[0]);
                   
                  out.println("<b>Transport Status:</b>&nbsp"+trans+"<br><br/><br><b>Hostel Status:</b>&nbsp"+hostel+"<br><br/><br><b>Mess Status:</b>&nbsp"+mess);
                  out.println("</td>");
                  out.println("<td><center>");
                  out.println("<a href='EditAdmission.jsp?aid="+ab.getAddmissionId()+"&semail="+ab.getStudentEmail()+"&mobile="+ab.getStudentMobile()+"&rollno="+ab.getRollNumber()+"&courseid="+ab.getCourseId()+"&appno="+ab.getApplicationNo()+"&adimdate="+aapdate+"&entrydate="+ab.getEntryDate()+"&entryemail="+ab.getEntryEmail()+"&courname="+cb.getCourseName()+"&stream="+cb.getStream()+"&ssession="+ab.getStudentSession()+"&stuid="+sb.getStudentId()+"&stuname="+sb.getStudentName()+"&stugender="+sb.getGender()+"&addid="+adb.getAddressId()+"&add1="+adb.getAddress1()+"&add2="+adb.getAddress2()+"&pin="+adb.getPinCode()+"&statid="+stb.getStateId()+"&stat="+stb.getStateName()+"&counid="+cob.getCountryId()+"&couname="+cob.getCountryName()+"&catid="+cab.getCategoryId()+"&catname="+cab.getCategory()+"&photo="+sb.getPhotoName()+"&parid="+pb.getParentId()+"&fatname="+pb.getFatherName()+"&fatmobile="+pb.getFatherMobileNo()+"&motname="+pb.getMotherName()+"&motmobile="+pb.getMotherMobileNo()+"&fatoccu="+pb.getFatherOccupation()+"&motoccu="+pb.getMotherOccupation()+"&garname="+pb.getGuardianName()+"&guarrel="+pb.getRelation()+"&guarocc="+pb.getGuardianOccupation()+"&guarmobile="+pb.getGuardianMobileNo()+"&gaddid="+pb.getAddressId()+"&gadd1="+adbp.getAddress1()+"&padd2="+adbp.getAddress2()+"&pcountryid="+adbp.getCountryId()+"&pcountry="+cobp.getCountryName()+"&pstateid="+adbp.getStateId()+"&pstate="+stbp.getStateName()+"&ppin="+adbp.getPinCode()+"&acadid="+acb.getAcademicId()+"&highsch="+acb.getHighSchool()+"&highboard="+acb.getHighBoardName()+"&highmmax="+acb.getHighMaxMarks()+"&highomax="+acb.getHighMarksObtained()+"&intersch="+acb.getInterSchool()+"&interboard="+acb.getInterBoardName()+"&intermmax="+acb.getInterMaxMarks()+"&interomax="+acb.getInterMarksObtained()+"&other="+acb.getOther()+"&oboard="+acb.getOtherBoardName()+"&ommax="+acb.getOtherMaxMarks()+"&oomark="+acb.getOhterMarksObtained()+"&entrydate="+acb.getEntryDate()+"&facid="+fb.getFacilityId()+"&transstatus="+fb.getTransportationStatus()+"&hostel="+fb.getHostelStatus()+"&mess="+fb.getMessStatus()+"'><button class='btn btn-info'>Edit</button></a>");
                 // out.println("<br><br><a href='#'><button class='btn btn-danger' onclick='deleteEnquiry("+ab.getAddmissionId()+")'>Delete</button></a>");
                  out.println("</center></td>");
                  out.println("</tr>");
               }
           }
           else 
           {
               out.println("<tr>");
               out.println("<td colspan='3'>");
               out.println("<b>No Record Found</b>");
               out.println("</td>");
               out.println("</tr>");
           }
        }catch(Exception e){
            out.println(e);
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(AdmissionList.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(AdmissionList.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
